package com.atguigu.config;

import com.atguigu.constant.RedisConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
   相当于消费者
 */
@Component
public class ShopMessageReceiver {
    @Autowired
    private RedisTemplate redisTemplate;

    //把redis发送过来的消息进行一个处理--设置秒杀状态位
    public void receiveChannelMessage(String message) {
        //""24:1""  seckill:state:24
        message=message.replaceAll("\"","");
        String[] split = message.split(":");
        if (split.length==2) {
            //设置秒杀状态位
            redisTemplate.opsForValue().set(RedisConst.SECKILL_STATE_PREFIX+split[0],split[1]);
        }
    }
}
